<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@taglib prefix="s" uri="/struts-tags"  %>
<%
	String operation = request.getParameter("operation");
%>
<%@ page import="com.starbaba.core.web.constant.WebConstants"%>
<%@ page import="com.starbaba.system.user.model.UserVO"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
.table>th {
	vertical-align: center;
	background-color: grey;
}
input[type="radio"] {
   font-size: 100px;
   vertical-align:middle;
   margin-top:-2px; 
   margin-left:2px;
   margin-bottom:1px;
}
</style>
</head>
<body class="no-skin">
	<div class="page-content">
		<div class="page-content-area">
			<div class="row">
				<div class="col-xs-12 col-sm-12 widget-container-col">
					<div class="widget-box widget-color-blue" style="height: 440px;">
						<!-- #section:custom/widget-box.options.collapsed -->
						<div class="widget-header widget-header-small">
							<h6 class="widget-title lighter">
								<i class="ace-icon glyphicon glyphicon-th-list"></i>添加一级项
							</h6>
							<div class="widget-toolbar no-border">
								<a href="#" data-action="collapse"> <i
									class="ace-icon fa fa-chevron-up"></i>
								</a>
							</div>
						</div>

						<div class="widget-body">
							<div class="widget-main" style="height: 400px;">
								<form class="form-horizontal" id="product-form"
									name="product-form" method="post" enctype="multipart/form-data">
									<div>
										<div style="text-align: left">
											<label for="from">实现方式</label><br>
											<s:select name="type_id" id="type_id" headerKey="" headerValue="请选择" list="%{paramsMap.typeList}" listKey="id" listValue="type_name" cssClass="form-control"></s:select>
										</div>
										<br>
										<div style="text-align: left">
											<label for="from">所属大项</label><br>
											<s:select name="project_id" id="project_id" headerKey="" headerValue="请选择" list="%{paramsMap.projList}" listKey="id" listValue="title" cssClass="form-control"></s:select>
										</div>
										<br>
										<div style="text-align: left">
											<label for="from">一级项名</label><br>
											<input type="text" name="title" id="title" placeholder="" class="col-xs-12 col-sm-12"/>
										</div>
										<br>
										<div style="text-align: left">
											<label for="from">一级项key名</label><br>
											<input type="text" name="data_key" id="data_key" placeholder="注意：不能和其他内部key名重复" class="col-xs-12 col-sm-12"/>
										</div>
										<br>
									</div>
								</form>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn  btn-inverse  no-border " onclick="doCancle()"
						id="delete">
						<i class="ace-icon fa fa-undo bigger-160"></i> 取消
					</button>
					&nbsp; &nbsp; &nbsp;
					<button id="btn-save" name="btn-save"
						class="btn  btn-success  no-border" type="button"
						onclick="doSave()">
						<i class="ace-icon fa fa-floppy-o bigger-160"></i> 保存
					</button>
				</div>
			</div>
		</div>
	</div>

	<%@ include file="/common/common-js.jsp"%>
	<%@ include file="/discovery/maxlength.jsp"%>
	<script type="text/javascript" src="${ctx}/ace/js/maxlength.js"></script>
	<script type="text/javascript" src="${ctx}/js/wangEditor-1.3.11.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery.form.js"></script>
	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
	<script>
		var $multiple = 1;
		var $selector = '';
		var $input = '';

		$(function() {
			$('#img').change(function() {
				var file = this.files[0];
				var r = new FileReader();
				r.readAsDataURL(file);
				$(r).load(function() {
					$('#thumbnail').attr('src', this.result);
					$('#img').attr("value", this.result);
				});
			});

			//点击按钮
			$('.get-img-modal').on('click', function() {
				//展示模态框
				var $this = $(this);
				var $title = $this.attr('data-title');
				$input = $this.attr('data-input');
				$selector = $this.attr('data-selector');
				$multiple = $this.attr('data-multiple');
				if ($multiple == 1) {
					$('input[name="myFile"]').prop('multiple', true);
				} else {
					$('input[name="myFile"]').prop('multiple', false);
				}
				$('#Modal').find('h4.modal-title').html($title);
				$('#Modal').modal('show');
				return false;
			});

			$('.thumbnail').on('click', function() {
				$('#thumbnail').attr('src', "");
				$("input[id=thumbnail]").val("");
			});

		});

		function insertHtml(dataList, selector, multiple) {
			var html = '';
			var iconClass = '';
			if (multiple == 0) {
				iconClass = 'change-btntext'
			}
			$.each(dataList, function(index, item) {
				html += '<div class="img-box">' + '<img src="' + item + '"/>'
						+ '<i class="fa fa-times ' + iconClass + '"></i>'
						+ '</div>';
			});
			if (multiple == 1) {
				$(selector).children('.view').removeClass('no-border').append(
						html);
			} else {
				$(selector).children('.view').removeClass('no-border').html(
						html);
			}
		}

		function doCancle() {
			try {
				if (parent) {
					parent.parent['__extdialog_active'].dialog('close');
				}
			} catch (e) {
				window.history.back();
			}
		}

		function doSave() {
			if(isBlock($("#type_id").val())){
				parent.bootbox.alert("请选择实现方式");
				return;
			}
			if(isBlock($("#project_id").val())){
				parent.bootbox.alert("请选择所属大项");
				return;
			}
			if(isBlock($("#title").val())){
				parent.bootbox.alert("请输入一级项名");
				return;
			}
			if(isBlock($("#data_key").val())){
				parent.bootbox.alert("请输入一级项key名");
				return;
			}
			saveForm();
		}

		function saveForm() {
			var saveUrl = ctx + "/apiModelBasisConf/saveItem.action";
			var options = {
				url : saveUrl,
				type : "POST",
				dataType : "json",
				beforeSend : function() {
					$(".load_bg,.load_img").show();
				},
				success : function(data) {
					parent.parent['__extdialog_active'].dialog('close');
					parent.query_any();
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert(textStatus);
					console.log(XMLHttpRequest, textStatus, errorThrown);
				},
				complete : function() {
					$(".load_bg,.load_img").hide();
				}
			};
			$('form[name="product-form"]').ajaxSubmit(options);
		}
		
		function isBlock(value){
			if(value==""||value==null||value==undefined){
				return true;
			}
			return false;
		}
	</script>
</body>
</html>
